package com.rtf.framework.mq.rocketmq.consumer.listener;

import java.util.List;

import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
import org.apache.rocketmq.common.message.MessageExt;

import com.rtf.framework.mq.common.MessageConsumer;

public class MessageConsumerOrderListener implements MessageListenerOrderly {

	private MessageConsumer consumer;

	public MessageConsumerOrderListener(MessageConsumer consumer) {
		this.consumer = consumer;
	}

	@Override
	public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {

		boolean result = this.consumer.onMessage(msgs.get(0));
		if (result)
			return ConsumeOrderlyStatus.SUCCESS;
		else
			return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
	}

}
